﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TSFUC
    {
        
        #region ==dwFUNC===========
        public static readonly DependencyProperty dwFUNCProperty = DependencyProperty.Register("dwFUNC",
            typeof(DataRow), typeof(TSFUC),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwFUNCChanged));
        public DataRow dwFUNC
        {
            get
            {
                return (DataRow)GetValue(dwFUNCProperty);
            }
            set
            {
                SetValue(dwFUNCProperty, value);
            }
        }
        private static void OdwFUNCChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TSFUC;
            if (src != null)
            {
                DataRow row= (DataRow)e.NewValue;
                src.dwFUNC = row; 
            }
        }
        #endregion
       
        public TSFUC()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            MV = new VICC_FUNCTIONS();
            DataContext = MV;
            InitializeComponent(); 
        } 
        
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded) return;
            LOADALL();
            base.Window_Loaded(sender, e);           
        }

        public void LOADALL()
        {
            dwData = TBMain.NewRow();
            dwData["MANDANT"] = app.Mandant;
            dwData["FULLNAME"] = " AND FULLNAME NOT LIKE 'gp%'";
            SResult = ((VICC_FUNCTIONS)MV).QueryICC_FUNCTIONS(dwData, -1);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                row["DES"] = row["FULLNAME"].ToString().Trim() + Helpers.Helper.GetGB2312Value(row["DESCRIPTION"].ToString().Trim());
            }
            MergeData(SResult,false); 
        }
        public override void LOADBYAUF()
        {
            Locate("KEY",ORDERNUM); 
        }
    }
}
